<template>
  <div class="loginConetnt">
    <div class="login">
      <a-form
        :model="formState"
        name="basic"
        :label-col="{ span: 2 }"
        :wrapper-col="{ span: 6 }"
        autocomplete="off"
        @finish="onFinish"
        @finishFailed="onFinishFailed"
      >
        <a-form-item
          label="账号"
          name="username"
          :rules="[{ required: true, message: 'Please input your username!' }]"
        >
          <a-input v-model:value="formState.username" />
        </a-form-item>

        <a-form-item
          label="密码"
          name="password"
          :rules="[{ required: true, message: 'Please input your password!' }]"
        >
          <a-input-password v-model:value="formState.password" />
        </a-form-item>

        <a-form-item name="remember" :wrapper-col="{ offset: 2, span: 6 }">
          <a-checkbox v-model:checked="formState.remember">记住密码</a-checkbox>
        </a-form-item>

        <a-form-item :wrapper-col="{ offset: 2, span: 6 }">
          <a-button type="primary" html-type="submit">登录</a-button>
        </a-form-item>
      </a-form>
    </div>
  </div>
</template>
<script setup lang="ts">
import router from "@/router";
import { defineComponent, reactive } from "vue";
import { message } from "ant-design-vue";
// import { useStore } from 'vuex';
import { userStoreX } from "@/store/modules/user";

const userStoreY: any = userStoreX();

interface FormState {
  username: string;
  password: string;
  remember: boolean;
}
const formState = reactive<FormState>({
  username: "",
  password: "",
  remember: true,
});
const onFinish = (values: any) => {
  if (values.username === "ironman" && values.password === "123..") {
    console.log("Success:", values);
    sessionStorage.setItem("user", JSON.stringify(values));
    userStoreY.changeUser(values);
    router.push("/index/button");
  } else {
    message.info("账号或者密码错误");
  }
};

const onFinishFailed = (errorInfo: any) => {
  console.log("Failed:", errorInfo);
};
</script>

<style lang="less" scoped>
.loginConetnt {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: url("@/assets/background2.jpeg") no-repeat;
  background-size: 100% 100%;

  .login {
    width: 1000px;
    // wid
  }
}

.ant-form-item {
  display: flex;
  justify-content: center;
  align-items: center;
}

.ant-btn-primary {
  width: 100%;
}
</style>
